home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
trap13.arc
/
TRAP13.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-04-09
|
10KB
|
355 lines
name Td
page 63,110
CODE segment
assume CS:CODE
Td proc far
org 100h ; .COM file
start: jmp instal ; to install code
savint: dd ? ; save old tick addr
doing: dw ? ; routine execute status
calmsg: db '*calling* from: '
rtmsg: db '*return* '
save: dw 6 dup(?) ; to store regs
saveCS: dw ?
saveIP dw ?
ourst: db 24 dup('stack ')
estack: db 0
ostseg: dw ? ; to save caller's stack
ostofs: dw ?
tdsig dw 7777h
dw 8888h
dw 9999h
dw 0aaaah
dw 0deadh
tdres proc near
push ax
push bp ; get caller's address
mov bp,sp
mov ax,word ptr [bp+4]
mov word ptr [saveIP], ax
mov ax, word ptr [bp+6]
mov word ptr [saveCS], ax
pop bp
pop ax
push ax
push ds ; save environment
pushf
push cs ; our data seg
pop ds
cmp byte ptr [doing],00h ; can we execute?
jz tdgk
jmp tdext
tdgk: mov byte ptr [doing],0ffh ; sure, we can execute
mov word ptr [save],ax ; save more stuff
mov word ptr [save+4],cx
cli ; no interrupts
mov ax,ss ; during stack munch
mov ostseg,ax
mov ostofs,sp
mov ax,ds ; point to our stack
mov ss,ax
mov sp,offset estack
sti
call sr ; calling message
mov cx,17
mov si, offset calmsg
call pfc
mov ax,word ptr[saveCS]
call pword
mov al,':'
mov ah,0
int 17h
mov ax,word ptr[saveIP]
call pword
call pcrlf
call dispr ; print caller's regs
; call pcrlf
call rr
mov ax,word ptr[save] ; get his args
mov cx,word ptr[save+4]
pushf
call dword ptr [savint] ; simulate an OLD int
mov word ptr [save], ax ; save return args
mov word ptr [save+4],cx
call sr ; save regs
mov cx,9 ; print return regs
mov si,offset rtmsg
call pfc
call pcrlf
call dispr
call pcrlf
call rr ; restore
cli
mov ax,ostseg ; retrieve normal stack
mov ss,ax
mov sp,ostofs
sti
mov cx,word ptr [save+4] ; cx too
tdext: popf
pop ds ; retreive environment
pop ax
mov ax,word ptr [save+10] ; return flags
push ax
popf
pop ax ; junk caller's ip
pop ax ; junk his CS
pop ax ; finally his flags
pushf ; give him OURS
mov ax, word ptr[saveCS] ; and his CS back
push ax
mov ax, word ptr[saveIP] ; and his IP
push ax
mov ax, word ptr[save] ; former INT13's AX result
mov byte ptr [doing],00h ; no longer executing
iret ; adios
ascii db '0123456789abcdef'
regs db ' AX BX CX DX ES '
Flags db ' Carry: '
dispr: mov si,0 ; save regs in core
inc si
inc si
mov word ptr [save+si],bx
inc si
inc si
inc si
inc si
mov word ptr [save+si],dx
inc si
inc si
push es
pop ax
mov word ptr [save+si],ax
inc si
inc si
pushf
pop ax
and ax,1
mov word ptr [save+si],ax
mov cx,5 ; 5 regs to print
cld
mov si, offset regs ; point to names
mov di, offset save ; and values
dpl: push cx
mov cx,4 ; name is 4 long
call pfc ; print it
mov ax,word ptr [di] ; next reg value
push cx ; print value
call pword
pop cx
inc di ; next value
inc di
pop cx ; restore counter
loop dpl ; do it again
mov cx,9 ; flags message
mov si, offset flags
call pfc
mov ax,word ptr [di]
call pword
call pcrlf
ret
pword: mov cl,8 ; sloppy print hex word
ror ax,cl ; routine follows
mov ch,ah
push cx
call pbyte
pop cx
mov ah,ch
ror ax,cl
call pbyte
ret
pbyte: mov cl,4
ror al,cl
push cx
call phdig
pop cx
ror al,cl
call phdig
ret
phdig: mov cl,al
and al,0fh
mov bx,offset ascii
xlat ascii
mov ah,0
int 17h
mov al,cl
ret
pfc: push ax ; print a string pointed to
plfc: mov ah,0 ; by SI, CX long
lodsb ;
int 17h
loop plfc
pop ax
ret
crlf: db 0dh
db 0ah
pcrlf: push si ; obviously
push cx
mov cx,2
mov si, offset crlf
call pfc
pop cx
pop si
ret
sr: pop ax ; cool save regs routine
pushf ; in real life, use :
push bx ;
push cx ; push ax
push dx ; call sr
push si ; .
push di ; .
push bp ; .
push es ; call rr
push ds ; pop ax
;
push ax
ret
rr: pop ax
pop ds ; restore regs
pop es
pop bp
pop di
pop si
pop dx
pop cx
pop bx
popf
push ax
tdend: ret
tdall: nop ; "offset + 1" of res
tdres endp
tdlen equ tdend-tdres ; routine length
siglen equ tdres-tdsig ; check length
intoff equ (13h*4)+0 ; addr of tick vector
intseg equ (13h*4)+2 ;
instal: push ds ; save DOS return word
xor ax,ax ; clear out ax
push ax ; for return
push ax ; and to zero ES
pop es
mov ax,es:[intoff] ; get tick vector offset
push ax ; move into di
pop di
sub di,siglen ;
mov ax,es:[intseg] ; get tick vector seg
push ax ; move into es
pop es ;
mov si,offset tdsig ; get our routine's address
cld ; forward compare
mov cx,siglen ; length of routine
rescmp: cmps ds:byte ptr[si],es:[di] ; loop while Z
loopz rescmp
jz reserr ; if all equal, already res.
xor ax,ax ; segment 0000
push ax
pop es
mov ax,word ptr es:[intoff] ; get tick vector offset
mov bx,offset savint
mov word ptr [bx],ax ; store tick routine's offset
mov ax,word ptr es:[intseg] ; get tick routine's segment
inc bx
inc bx
mov word ptr [bx],ax ; store
mov byte ptr [doing], 0ffh ; fake executing
cli ; no interrupts while
mov word ptr es:[intoff], offset tdres ; storing
mov word ptr es:[intseg], cs ; vectors
sti ; interrupts Again
mov dx,offset resmsg ; good msg
mov ah,9 ; output string
int 21h ; display
mov doing, 00h ; allow executing
mov dx,tdall ; our resident portion
int 27h ; terminate & stay resident
reserr: mov dx,offset errmsg ; error msg
mov ah,9 ; output string
int 21h ; display
int 20h ; go home
Td endp
resmsg: db 'TRAP13 - (c) 1985 Eric Pederson - Resident portion loaded'
db '$'
errmsg: db 'TRAP13 - Already resident'
db '$'
CODE ends
end start